//
//  GiftMessageDataSource.m
//  tcpoctest
//
//  Created by gump on 6/4/13.
//  Copyright (c) 2013 gump. All rights reserved.
//

#import "GiftMessageDataSource.h"

#import "giftMessageInfo.h"

@implementation GiftMessageDataSource

-(id)init
{
    self = [super init];
    
    if (self != nil) {
        GMarr = [[NSMutableArray alloc] init];
        self.curSelectInfo = nil;
        
        pthread_mutex_init(&mutexGM, 0);
    }
    
    return self;
}

-(void)AddGiftMessage:(giftMessageInfo *)gminfo
{
    pthread_mutex_lock(&mutexGM);
    
    [GMarr addObject:gminfo];
    
    pthread_mutex_unlock(&mutexGM);
}

-(giftMessageInfo *)GetInfoByIndex:(int)iindex
{
    giftMessageInfo *gminfo = nil;
    
    pthread_mutex_lock(&mutexGM);
    
    if (iindex >= 0 && iindex < GMarr.count) {
        gminfo = [GMarr objectAtIndex:iindex];
    }
    
    pthread_mutex_unlock(&mutexGM);
    
    return gminfo;
}

-(void)delAllMessage
{
    pthread_mutex_lock(&mutexGM);
    
    [GMarr removeAllObjects];
    
    pthread_mutex_unlock(&mutexGM);
}

@end
